package com.box.modules.report.controller;

import com.box.common.utils.R;
import com.box.common.validator.ValidatorUtils;
import com.box.modules.report.service.BoxRowDataService;
import com.box.modules.report.vo.ReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangjs
 * @email catalpa65@163.com
 * @date 2020-10-23
 */
@Api(tags = "上报相关")
@RestController
@RequestMapping("device")
public class ReportController {

    @Autowired
    BoxRowDataService boxRowDataService;

    @ApiOperation("流量数据上报接口")
    @PostMapping("/reportDataFlow")
    public R list(@RequestBody ReportVO reportVO) {
        ValidatorUtils.validateEntity(reportVO);

        //判断业务类型
        if (!reportVO.getBizType().equals("1")) {
            return R.error("业务类型(bizType)错误：1-流量上报");
        }
        //判断流水号是否重复
        if (boxRowDataService.checkMessageId(reportVO.getMessageId())) {
            return R.error("该流水记录已上传");
        }

        Boolean result = boxRowDataService.addReport(reportVO);
        if (result == true) {
            return R.ok();
        } else {
            return R.error("上传失败，请重试");
        }
    }

}
